package com.spagettikod.t437.component;

import java.awt.Color;
import java.awt.Component;
import java.awt.SystemColor;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.spagettikod.SystemUtil;
import com.spagettikod.t437.T437;
import com.spagettikod.t437.simpledb.SimpleDBAttribute;

public class SimpleDBAttributeTableCellRenderer extends JLabel implements
		TableCellRenderer {

	private static final long serialVersionUID = -4525018746484867477L;

	public SimpleDBAttributeTableCellRenderer() {
		super();
		setOpaque(true);
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		SimpleDBAttribute attr = (SimpleDBAttribute) value;
		if (attr == null) {
			setText("");
		} else {
			setText(attr.toString());
			if (attr.hasMultipleValues()
					&& T437.getConfigurator()
							.getSDBMultipleBackgroundColorize()) {
				setBackground(Color.YELLOW);
			} else {
				setBackground(Color.WHITE);
			}
		}
		if (isSelected && attr != null) {
			if(SystemUtil.isMacOSX()) {
			setBackground(SystemColor.controlHighlight);
			setForeground(SystemColor.controlLtHighlight);
			} else {
				setBackground(SystemColor.textHighlight);
				setForeground(SystemColor.textHighlightText);
			}
		} else {
			setBackground(SystemColor.text);
			setForeground(SystemColor.textText);
		}
		return this;
	}

}
